<?php
namespace App\Models\Factory;

use App\Models\AbsModelFactory;
use App\Models\Orm\Tb_deliver_addrs;
use App\Models\Orm\Tb_order;
use App\Models\Orm\Tb_user;
use App\Models\Orm\Tb_zhifubao_binding;
use App\Models\Orm\TbDeliverAddrs;
use App\Models\Orm\TbOrder;
use App\Models\Orm\TbUser;
use App\Models\Orm\TbZhifubaoBinding;


/**
 * Class TaoBaoFactory
 * @package App\Models\Factory
 */
class TaoBaoFactory extends  AbsModelFactory
{

    //淘宝个人信息表里添加数据
    public static function addtbuser($data)
    {
        $time = date("Y-m-d H:i:s",time());
        $data['created_at'] = $time;
        $res = TbUser::firstOrCreate(['uid'=>$data['uid']],$data);
       return  $res? true:false;

    }

    //往淘宝的订单表里插入数据
    public static function addorder($data,$uid)
    {

        //查看生成的数组大小
        $i = count($data);
        if($i){

            foreach($data as $order){
                $order['uid'] = $uid;
                $time = date("Y-m-d H:i:s",time());
                $order['created_at'] = $time;
                $order['products'] = json_encode($order['products']);
                $res = TbOrder::firstOrCreate(['uid'=>$uid],$order);
                if(!$res){
                    continue;
                }
            }
            $call_log = TbOrder::all()->first();
            return empty($call_log)? false :true;
        }
    }

    //淘宝收货地址表里添加数据
    public static function adddeliver($data,$uid)
    {

        //查看生成数组大小
        $i = count($data);
        if($i) {

            foreach($data as $deliver){
                $deliver['uid'] = $uid;
                $time = date("Y-m-d H:i:s",time());
                $deliver['created_at'] = $time;
                $res = TbDeliverAddrs::firstOrCreate(['uid'=>$uid],$deliver);
                if(!$res){
                    continue;
                }
            }
            $sms_log = TbDeliverAddrs::all()->first();
           return  empty($sms_log)? false :true;
        }


    }

    //淘宝支付宝绑定账号里添加数据
    public static function addbinding($data,$uid)
    {
        //查看生成数组大小
        $data['uid'] = $uid;
        $time = date("Y-m-d H:i:s",time());
        $data['created_at'] = $time;
        $res = TbZhifubaoBinding::firstOrCreate(['uid'=>$uid],$data);
       return  $res? true:false;
    }

}